//
//  GYhomeBuyDetailViewModel.m
//  GYDemo
//
//  Created by Mrzhang on 2018/4/3.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "GYhomeBuyDetailViewModel.h"
#import "Head.h"

@implementation GYHomeBuyDetialProductListInfoModel
@end
@implementation GYhomeBuyDetailInfoModel

@end

@implementation GYhomeBuyDetailViewModel
-(instancetype)init
{
    if (self = [super init]) {
        //添加接口特殊处理
        [[InterfaceManager shareInterface].specialInterfaces addObject:@"judgeProductIsCollected"];
        _isCollect=NO;
    }
    return self;
}
-(NSMutableArray *)productData
{
    if (!_productData) {
        _productData=[[NSMutableArray alloc] init];
    }
    return _productData;
}
-(GYhomeBuyDetailInfoModel *)buyDetailInfoModel
{
    if (!_buyDetailInfoModel) {
        _buyDetailInfoModel=[[GYhomeBuyDetailInfoModel alloc]
                             init];
    }
    return _buyDetailInfoModel;
}
#pragma requst
-(void)requestDetai:(NSMutableDictionary *)para
{
    //mySaleProduct
    @WeakSelf;
    NSString *interface = @"buyProductDetail";
    [[InterfaceManager shareInterface]requetInterface:interface withParameter:para handler:^(NSDictionary *info, InterfaceStatusModel *infoModel) {
        NSDictionary *data = infoModel.data;
        if ([data isKindOfClass:[NSDictionary class]]) {
            GYhomeBuyDetailInfoModel *model = [GYhomeBuyDetailInfoModel yy_modelWithJSON:data];
            [selfp setBuyDetailInfoModel:model];
        }
    }];
}


-(void)requestProductList:(NSMutableDictionary *)para
{
    @WeakSelf;
    NSString *interface = @"mySaleProduct";
    NSString *page = para[@"page"];
    [[InterfaceManager shareInterface]requetInterface:interface withParameter:para handler:^(NSDictionary *info, InterfaceStatusModel *infoModel) {
        NSDictionary *data = infoModel.data;
        if ([data isKindOfClass:[NSDictionary class]])
        {
            NSArray *datalist = data[@"datalist"];
            
            if ([datalist count]<10) {
                selfp.canAddMore=NO;
            }else
            {
                selfp.canAddMore=YES;
            }
            
            if ([datalist isKindOfClass:[NSArray class]]) {
                
                NSMutableArray *arr;
                if ([page isEqualToString:@"1"]) {
                    arr = [NSMutableArray new];
                }else{
                    arr = _productData;
                }
                
                for (NSDictionary *dic in datalist) {
                    GYHomeBuyDetialProductListInfoModel *model = [GYHomeBuyDetialProductListInfoModel yy_modelWithJSON:dic];
                    [arr addObject:model];
                }
                [selfp setProductData:arr];
                
            }
        }
        
    }];
}

-(void)requestCheckCollect:(NSMutableDictionary *)para
{
    @WeakSelf;
    NSString *interface = @"judgeProductIsCollected";
    [[InterfaceManager shareInterface]requetInterface:interface withParameter:para handler:^(NSDictionary *info, InterfaceStatusModel *infoModel) {
        if ([info isKindOfClass:[NSDictionary class]]) {
            
            if ([[info objectForKey:@"status"] integerValue]==1)
            {
                [selfp setIsCollect:NO];
            }else
            {
                [selfp setIsCollect:YES];
            }
            
        }
    }];
}
@end
